<?php
/* @var $this BaigiangController */
/* @var $model Bài Giảng */
/* @var $form CActiveForm */
?>


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'bai-giang-form',
	'enableAjaxValidation'=>false,
        'htmlOptions'=>array(
                'enctype'=>'multipart/form-data'
        )
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo $form->textField($model,'name',array('size'=>40,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

        
        <div class="row" id="input-file-thumbnail" style="<?php if(!$model->isNewRecord) echo 'display:none' ?>">
		<?php echo $form->labelEx($model,'thumbnailFile'); ?>
		<?php echo $form->fileField($model, 'thumbnailFile', array('style'=>'width:200px')); ?>
		<?php echo $form->error($model,'thumbnailFile'); ?>
	</div>
                
        <div class="row" id="cancel-file-thumbnail" style="display:none">
                <?php echo CHtml::button('Cancel File', array('id'=>'btn-cancel-file-thumbnail')) ?>
        </div>
        
        <div class="row" id="thumbnail-image" style="<?php if($model->isNewRecord) echo 'display:none' ?>">
                <?php echo CHtml::image($model->thumbnailUrl?Utils::createAbsoluteUrl($model->thumbnailUrl):Path::getDefaultBaiGiangThumbnailUrl(), '', array('width'=>'200px', 'height'=>'200px')) ?>
        </div>
                
        <div class="row" id="change-file-thumbnail" style="<?php if($model->isNewRecord) echo 'display:none' ?>">
                <?php echo CHtml::button('Change Thumbnail', array('id'=>'btn-change-file-thumbnail')) ?>
        </div>
	
	<div class="row">
		<?php echo $form->labelEx($model,'khoihocId'); ?>
		<?php echo $form->dropDownList($model, 'khoihocId', CHtml::listData($khoihocs, 'id', 'name')); ?>
		<?php echo $form->error($model,'khoihocId'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'monhocId'); ?>
		<?php echo $form->dropDownList($model, 'monhocId', CHtml::listData($monhocs, 'id', 'name'), array('id'=>'sl-monhoc')); ?>
		<?php echo $form->error($model,'monhocId'); ?>
	</div>
        
        <?php $monhocChilds=array() ?>
        <?php if(!$model->isNewRecord){
                $monhocChilds=  MonHocChild::model()->findAllByAttributes(array('monhocId'=>$model->monhocId));
        } ?>
        
        <div class="row" id="monhoc-child-input" style="<?php if($model->isNewRecord || empty($monhocChilds))echo 'display:none' ?>">
		<?php echo $form->labelEx($model,'monhocChildId'); ?>
		<?php echo $form->dropDownList($model, 'monhocChildId', CHtml::listData($monhocChilds, 'id', 'name'), array('id'=>'sl_monhocchild')); ?>
		<?php echo $form->error($model,'monhocChildId'); ?>
	</div>
        
        <div class="row">
                <?php echo $form->labelEx($model,'description'); ?>
                <?php 
                    $this->widget('application.extensions.markitup.EHtmlEditor', array(
                            'model'=>$model,
                            'attribute'=>'description',
                            'theme'=>'markitup',
                        'settings'=>'html',
                            'htmlOptions'=>array('rows'=>15, 'cols'=>70),
                            ));
                 ?>
                <?php echo $form->error($model,'description'); ?>
        </div>
        
        <div class="row" id="input-file-baigiang" style="<?php if($model->linkurl) echo 'display:none' ?>">
		<?php echo $form->labelEx($model,'file'); ?>
		<?php echo $form->fileField($model, 'file', array('style'=>'width:200px')); ?>
		<?php echo $form->error($model,'file'); ?>
	</div>
        
        <div class="row" id="cancel-file-baigiang" style="display:none">
                <?php echo CHtml::button('Cancel File', array('id'=>'btn-cancel-file-baigiang')) ?>
        </div>
        
        <div class="row" id="link-baigiang" style="<?php if(!$model->linkurl) echo 'display:none' ?>">
                <?php echo $form->labelEx($model,'linkurl'); ?>
                <?php echo CHtml::link('View', Utils::createAbsoluteUrl($model->linkurl), array('target'=>'_blank')) ?>
                <?php echo CHtml::link('Change', '', array('id'=>'change-baigiang')) ?>
        </div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<script type="text/javascript">
        $(function(){
                $('#sl-monhoc').change(function(){
                        $.ajax({
                                'url':'<?php echo Yii::app()->createUrl('/admin/monhocchild/getSelectHtmlOptions') ?>/monhocId/'+$(this).val(),
                                'success':function(data){                                        
                                        $('#sl_monhocchild').html(data);
                                        if(data){
                                                $('#monhoc-child-input').show();
                                        }else{
                                                $('#monhoc-child-input').hide();
                                        }
                                        
                                }
                        });
                });
                
                $('#change-baigiang').click(function(){
                        $('#link-baigiang').hide();
                        $('#input-file-baigiang').show();
                        $('#cancel-file-baigiang').show();
                });
                
                $('#btn-cancel-file-baigiang').click(function(){
                        $('#link-baigiang').show();
                        $('#input-file-baigiang').hide();
                        $('#cancel-file-baigiang').hide();
                });
                
                $('#btn-change-file-thumbnail').click(function(){
                        $('#input-file-thumbnail').show();
                        $('#cancel-file-thumbnail').show();
                        $('#thumbnail-image').hide();
                        $('#change-file-thumbnail').hide();
                });
                
                $('#btn-cancel-file-thumbnail').click(function(){
                        $('#input-file-thumbnail').hide();
                        $('#cancel-file-thumbnail').hide();
                        $('#thumbnail-image').show();
                        $('#change-file-thumbnail').show();
                });
                
                <?php if($model->isNewRecord){ ?>
                        $('#sl-monhoc').change();
                <?php } ?>
        });
</script>

 